<?php
require 'emos/init.php';

use Emos\Field;
use Emos\Db;
use Emos\Editor;
use Emos\ListField;

Emos\Common::setDeveloperMode();

session_start();

//$db = new Db\MySqli(array('database'=>'emos'));
$db = new Db\Oci(array('user'=>'emos', 'password'=>'password', 'connection_string'=>'192.168.1.38/XE'));


$pageEnt = new Editor\Entity('shop_page', 'id');
//$pageEnt->addColumn('icon', null, new ListField\Icon());		
//$pageEnt->addColumn('title');
//$pageEnt->allowActions(false, false, false);
$pageEnt->addField('title', 'title', new Field\Text());
$pageEnt->addField('password', 'password', new Field\Password('no'));
$pageEnt->addField('status', 'status', new Field\Choice(array('normal'=>'Normal', 'hidden'=>'Hidden', 'off'=>'Off'), 'radio_horizontal'));
$pageEnt->addField('datetime', 'date and time', new Field\DateTime());
$pageEnt->addField('text', null, new Field\CKEditor())->setToolbar('Basic');
$pageEnt->setMoveField('sort');

$shopEnt = new Editor\Entity('shop_shop', 'id');
//$shopEnt->addColumn('id');		
//$shopEnt->addColumn('title');
$shopEnt->addField('title', 'title', new Field\Text())->setRegexp("/^[a-z|\s]+$/ui", "Only lat!");
$shopEnt->addField('text', 'text', new Field\Textarea())->setNullable();
$shopEnt->addField('services', 'services', new Field\MultiChoice(array('refull'=>'refull', 'repair'=>'repair', 'update'=>'update', 'other'=>'other'), 'checkboxes_horizontal'));
$shopEnt->addField('file', 'file', new Field\File());
$shopEnt->addField('image', 'image', new Field\Image())->addVersion(100,100)->addVersion(300,300);
$shopEnt->addField('gps', 'gps', new Field\LatLng())->setNullable();
$shopEnt->setDefaultRecord(array('gps_lat'=>59.95000001, 'gps_lng'=>30.316666676667, 'title'=>'New shop'));

$categoryEnt = new Editor\Entity('shop_category', 'id');
//$categoryEnt->addColumn('id');		
//$categoryEnt->addColumn('title');
//$categoryEnt->setWhere("title LIKE 'c%'");
$categoryEnt->addColumn(null, null, new ListField\Glyph('[K]'));		
$categoryEnt->addColumn('title');
$categoryEnt->addField('title', 'title', new Field\Text());
$categoryEnt->setMoveField('sort');

$itemEnt = new Editor\Entity('shop_item', 'id');
$itemEnt->addColumn('id');		
$itemEnt->addColumn('title');
$itemEnt->addColumn('price', 'Price', new ListField\Number())->setSprintf('%.2f $');
$itemEnt->addColumn('qty');
$itemEnt->addField('title', 'title', new Field\Text());
$itemEnt->addField('price', 'price', new Field\Float())->setRange();
$itemEnt->addField('qty', 'qty', new Field\Integer())->setRange(-10, 50);
$itemEnt->addField('image', 'image', new Field\Image())->addVersion(100,100);
$itemEnt->setDefaultRecord(array('price'=>12.34));

$photoEnt = new Editor\Entity('shop_photo', 'id');
$photoEnt->addColumn('id');		
$photoEnt->addColumn('title');
$photoEnt->addField('title', 'title', new Field\Text());
$photoEnt->setMoveField('sort');

$articleEnt = new Editor\Entity('shop_article', 'id');
$articleEnt->addColumn('id');		
$articleEnt->addColumn('title');
$articleEnt->addField('title', 'title', new Field\Text());

$tree = new Editor\Tree();
$tree->setMainHeight(500);
$tree->setDb($db);
$tree->addEntity($pageEnt);
$tree->addEntity($shopEnt);
    $shopEnt->addEntity($categoryEnt, 'shop_id');
        $categoryEnt->addEntity($categoryEnt, 'category_id');
        $categoryEnt->addEntity($itemEnt, 'category_id');
            $itemEnt->addEntity($photoEnt, 'item_id');
            $itemEnt->addEntity($articleEnt, 'item_id');        
$tree->init();
$tree->ajax();



